import { NextRequest, NextResponse } from "next/server";
import prisma from "../../../../lib/prisma";

export async function PUT(request: NextRequest) {
  try {
    const { userId, chatTitle, initialMessage } = await request.json();

    // 创建新聊天
    const newChat = await prisma.chat.create({
      data: {
        userId,
        chatTitle,
        messages: [initialMessage],
      },
    });

    return NextResponse.json({ chat: newChat });
  } catch (error) {
    return NextResponse.json({ error: "Server error" }, { status: 500 });
  }
}
